package com.freeseed.model.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.freeseed.model.entity.Transcript;
import com.freeseed.model.mapper.TranscriptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Allwayz
 * @since 2020-03-20
 */
@RestController
@RequestMapping("transcripts")
public class TranscriptController {
    @Autowired
    private TranscriptMapper transcriptMapper;

    @GetMapping
    public List<Transcript> getTranscriptList(){
        List<Transcript> transcriptList = transcriptMapper.selectList(new QueryWrapper<>());
        return transcriptList;
    }

    @GetMapping("{Id}")
    public Transcript getTranscriptById(@PathVariable int Id){
        Transcript transcript = transcriptMapper.selectById(Id);
        return transcript;
    }

    @PostMapping
    public Transcript addTranscript(Transcript transcript){
        transcriptMapper.insert(transcript);
        return transcript;
    }

    @PutMapping
    public Transcript updateTranscript(Transcript transcript){
        transcriptMapper.update(transcript,new UpdateWrapper<Transcript>().eq("transcript+id",transcript.getTranscriptId()));
        return transcript;
    }

    @DeleteMapping("{Id}")
    public void deleteTranscript(@PathVariable int Id){
        transcriptMapper.deleteById(Id);
    }
}
